
local attribute = require 'types.unit_attribute'
local field = attribute.field

local file = {}

setmetatable(file,file)


local mt = {}
file.__index = mt

--[添加单个属性]
function mt:add(key,num)
    self.attributes[key] = (self.attributes[key] or 0) + num
end

--[添加表格属性]
function mt:add_table(table)
    for key,num in ipairs(table) do
        if field[key] then
            self:add(key,num)
        end
    end
end

--[添加函数]
function mt:add_func(func)
    self.eventfunc[#self.eventfunc + 1] = func
end

--[设置存档英雄]
function mt:set_hero(hero)
    if self.removed then
        return
    end
    self.removed = true
    local player = self.player
    for key,num in pairs(self.attributes) do
        if field[key] then
            hero:add(key,num)
        end
    end
    for _,func in ipairs(self.eventfunc) do
        func(hero,player)
    end
    player:notify('玩家-刷新UI',player)
end

--[初始化]
function mt:init()
    self.attributes = {}
    self.eventfunc = {}
end